Skip to content

Enforce co-partitioning for sort merge and symmetric hash joins#23480

Open
gene-bordegaray wants to merge 1 commit into
apache:mainfrom
gene-bordegaray:gene.bordegaray/2026/07/co-partitioned-join-requirements
Open

Enforce co-partitioning for sort merge and symmetric hash joins#23480
gene-bordegaray wants to merge 1 commit into
apache:mainfrom
gene-bordegaray:gene.bordegaray/2026/07/co-partitioned-join-requirements

Conversation

@gene-bordegaray

@gene-bordegaray gene-bordegaray commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Partition-index-aware joins require compatible input layouts. Compatible Range layouts can satisfy that without repartitioning.

What changes are included in this PR?

  • Require co-partitioned children for sort-merge and partitioned symmetric hash joins.
  • Allow compatible Range inputs to satisfy those requirements.
  • Let streaming tables declare output partitioning and preserve it through scan projection.
  • Add sanity checks and range-partitioning SLT coverage.

Are these changes tested?

Yes

Are there any user-facing changes?

Streaming table providers can declare output partitioning with StreamingTable::with_output_partitioning().

@github-actions github-actions Bot added core Core DataFusion crate sqllogictest SQL Logic Tests (.slt) physical-plan Changes to the physical-plan crate labels Jul 11, 2026
.map(|exec| Arc::new(exec) as Arc<dyn ExecutionPlan>)
}

fn hash_partitioned_exec(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using hash to prove that co-partitioning dows work fro an accepted partitioning type

@gene-bordegaray gene-bordegaray marked this pull request as ready for review July 11, 2026 13:54
@gene-bordegaray

Copy link
Copy Markdown
Contributor Author

@stuhood @mithuncy @gabotechs

@stuhood stuhood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Comment on lines +427 to +430
InputDistributionRequirements::co_partitioned(vec![
Distribution::KeyPartitioned(left_expr),
Distribution::KeyPartitioned(right_expr),
]
])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add range-partitioning SLT coverage showing both joins repartitioned until their dedicated Range opt-in work lands.

Is it worth TODOs next to both of the uses of InputDistributionRequirements::co_partitioned linking to the relevant issues which will do it? Alternatively, would it be reasonably to inline that enabling? Otherwise it feels like this PR is nearly a noop.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's also my feeling after reviewing this PR, it seems to be doing close to nothing.

Rather than changing 2 LOC in symteric_hash_join.rs and sort_merge_join/mod.rs, and adding some tests demonstrating it still does not work, would it be too hard to actually make it work in this same PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ya that was prbably too small of changes per PR, I addressed this adding the support.

Comment on lines +655 to +660
03)----SortExec: expr=[range_key@0 ASC], preserve_partitioning=[true]
04)------RepartitionExec: partitioning=Hash([range_key@0], 4), input_partitions=4
05)--------DataSourceExec: file_groups=<slt:ignore>, projection=[range_key, value], output_partitioning=Range([range_key@0 ASC], [(10), (20), (30)], 4), file_type=csv, has_header=false
06)----SortExec: expr=[range_key@0 ASC], preserve_partitioning=[true]
07)------RepartitionExec: partitioning=Hash([range_key@0], 4), input_partitions=4
08)--------DataSourceExec: file_groups=<slt:ignore>, projection=[range_key, value], output_partitioning=Range([range_key@0 ASC], [(10), (20), (30)], 4), file_type=csv, has_header=false

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me how is it that, even if SortMergeJoinExec now requires both children to be co-partitioned, and the join is in the range_key, we are still seeing RepartitionExecs injected here? I bet this is tracked in an issue. Can we link the issue in the test description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is because I did not opt into the range satisfaction since it isn't general yet with: allow_range_satisfaction_for_key_partitioning()

I didn't do this just because I wanted to do the other operators first but with others picking those up I guess there is no reason fro me not to 👍

Comment on lines +427 to +430
InputDistributionRequirements::co_partitioned(vec![
Distribution::KeyPartitioned(left_expr),
Distribution::KeyPartitioned(right_expr),
]
])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's also my feeling after reviewing this PR, it seems to be doing close to nothing.

Rather than changing 2 LOC in symteric_hash_join.rs and sort_merge_join/mod.rs, and adding some tests demonstrating it still does not work, would it be too hard to actually make it work in this same PR?

@gene-bordegaray gene-bordegaray force-pushed the gene.bordegaray/2026/07/co-partitioned-join-requirements branch 2 times, most recently from 9eb6eb1 to c17f438 Compare July 14, 2026 13:58
@github-actions github-actions Bot added the catalog Related to the catalog crate label Jul 14, 2026
@gene-bordegaray gene-bordegaray force-pushed the gene.bordegaray/2026/07/co-partitioned-join-requirements branch from c17f438 to 80edd7c Compare July 14, 2026 14:05
///
/// `output_partitioning` must describe this plan's current output and have
/// the same number of partitions as the stream.
pub fn with_output_partitioning(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

surprised this wasn't avaialble before, wondering if there was a reason but could not think of why 🤔

@stuhood stuhood left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great: thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

catalog Related to the catalog crate core Core DataFusion crate physical-plan Changes to the physical-plan crate sqllogictest SQL Logic Tests (.slt)

Projects

None yet

3 participants